local skel = fk.CreateSkill {
  name = "efengqi__yanshen",
}

Fk:loadTranslationTable{
  ["efengqi__yanshen"] = "炎神",
  [":efengqi__yanshen"] = "摸牌阶段，你可以改为视为使用三张【火攻】，你因此受到伤害时改为摸两张牌。",

  ["#efengqi__yanshen-invoke"] = "炎神：你可以将摸牌阶段改为视为使用三张【火攻】",
  ["#efengqi__yanshen-use"] = "炎神：视为使用三张【火攻】（第 %arg 张），你受到此牌伤害时改为摸两张牌",

  ["$efengqi__yanshen1"] = "火莲绽江矶，炎映三千弱水。",
  ["$efengqi__yanshen2"] = "星火乘风，风助火势，其必成燎原之姿。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and player == target then
      if player.phase == Player.Draw and not data.phase_end then
        local card = Fk:cloneCard("fire_attack")
        card.skillName = skel.name
        return player:canUse(card) and not player:prohibitUse(card)
        and table.find(player.room.alive_players, function (p)
          return not p:isKongcheng()
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#efengqi__yanshen-invoke"})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.phase_end = true
    for i = 1, 3 do
      if player.dead then break end
      local use = room:askToUseVirtualCard(player, {
        name = "fire_attack", skill_name = skel.name, cancelable = false, skip = true,
        prompt = "#efengqi__yanshen-use:::"..i,
      })
      if not use then break end
      use.extra_data = use.extra_data or {}
      use.extra_data.efengqi__yanshen_user = player.id
      room:useCard(use)
    end
  end,
})

skel:addEffect(fk.DamageInflicted, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if data.card and table.contains(data.card.skillNames, skel.name) and not player.dead and data.to == player then
      local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if use_event then
        return (use_event.data.extra_data or Util.DummyTable).efengqi__yanshen_user == player.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, skel.name)
    data:preventDamage()
  end,
})

return skel
